<?php

namespace App\Models\cainiao;

use App\Models\base\WarehouseModel;
use App\Models\CountryModel;
use App\Models\customer\NodeModel;
use App\Models\customer\ResourceModel;
use App\Models\CustomerModel;
use App\Models\OrderModel;
use App\Models\TakeOrderModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;


class NotifyModel extends BaseModel
{
    use SoftDeletes;
    protected $table = 't_cainiao_notify';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';

    const PLATFORM = [1 => 'tm', 2 => 'lazada'];

    const STATUS_NEW = 1;
    const STATUS_RECEIVED = 2;
    const STATUS_CARGO = 3;
    const STATUS_EXPORT_CUSTOM_CLEARANCE_START = 4;
    const STATUS_EXPORT_CUSTOM_CLEARANCE_SUCCESS = 5;
    const STATUS_FORECAST = 6;
    const STATUS_FLIGHT = 7;
    const STATUS_UPLOADED = 8;
    const STATUS_ARRIVED = 9;
    const STATUS_CLEARANCE = 10;
    const STATUS_SHIPPED = 11;

    const STATUS = [
        1 => '新订单',
        2 => '已揽件',
        3 => '已配舱',
        4 => '出口报关开始',
        5 => '出口报关完成',
        6 => '已预报',
        7 => '已交航',
        8 => '已起飞',
        9 => '已到达',
        10 => '已清关',
        11 => '已派送'
    ];
    
    const UPDATED_AT = null;

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];

    //小包
    public function asn(): HasMany {
        return $this->hasMany(AsnModel::class, 'bigBagID', 'bigBagID');
    }

    //入仓单
    public function order(): BelongsTo {
        return $this->belongsTo(OrderModel::class, 'order_id');
    }

    //提单
    public function take_order(): BelongsTo {
        return $this->belongsTo(TakeOrderModel::class, 'take_order_id');
    }

    //客户
    public function customer(): BelongsTo {
        return $this->belongsTo(CustomerModel::class, 'customer_id');
    }

    //仓库
    public function warehouse(): BelongsTo {
        return $this->belongsTo(WarehouseModel::class, 'warehouse_id');
    }

    //系统节点
    public function system_node(): BelongsTo {
        return $this->belongsTo(NodeModel::class, 'system_node_id');
    }

    //平台节点
    public function platform_node(): BelongsTo {
        return $this->belongsTo(NodeModel::class, 'platform_node_id');
    }

    //目的地国家
    public function destination(): BelongsTo {
        return $this->belongsTo(CountryModel::class, 'des_country_id');
    }

    //集运仓
    public function con_warehouse(): BelongsTo {
        return $this->belongsTo(ResourceModel::class, 'con_warehouse', 'code');
    }

    //派送商
    public function delivery_provider(): BelongsTo {
        return $this->belongsTo(ResourceModel::class, 'delivery_provider', 'code');
    }

    //出口关务
    public function export_agent(): BelongsTo {
        return $this->belongsTo(ResourceModel::class, 'export_agent', 'code');
    }

}
